<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * Description of carsenal
 *
 * @author
 */
defined('ROOT') or die('No direct script access.');
class C{TemplateControllerName} extends CController
{
    public function action_list($param)
    {
        if (auth::authorized()) {
            $model = new {TemplateManagerName}();
            $list = $model->get_list();
            $data = array(
                'rows'  => $list['rows'],
            );
            $view = new CView();
            $view->assign($data);
            $view->display("{TemplateListName}.php");
        } else {
            self::redirect("");
        }
    }

    function action_add($param)
    {
        if (auth::authorized()) {
            $record = new {TemplateRecordName}();
            $data = array(
                '{TemplateFormRecordName}'  => $record,
            );
            $view = new CView();
            $view->assign($data);
            $view->display("{TemplateFormName}.php");
        } else {
            self::redirect("");
        }
    }

    public function action_edit($param)
    {
        if (auth::authorized()) {
            $rec_id = intval(self::escape($param['id']));
            $model = new {TemplateManagerName}();
            $record = $model->get_by_id($rec_id);
            $data = array(
                '{TemplateFormRecordName}'  => $record,
            );
            $view = new CView();
            $view->assign($data);
            $view->display("{TemplateFormName}.php");
        } else {
            self::redirect("");
        }
    }

    public function action_view($param)
    {
        if (auth::authorized()) {
            $rec_id = intval(self::escape($param['id']));
            $record = new {TemplateManagerName}();
            $record->get_by_id($rec_id);
            $data = array(
                '{TemplateFormRecordName}'  => $record,
            );
            $view = new CView();
            $view->assign($data);
            $view->display("{TemplateFormViewName}.php");
        } else {
            self::redirect("");
        }
    }

    public function action_save($param)
    {
        if (auth::authorized()) {
            $data = array(
                'path' => $param,
                'post' => $_POST,
            );
            $model = new {TemplateRecordName}();
            $model->set_form_values($data);
            $model->save();
            self::redirect("/{TemplateControllerPath}/list");
        } else {
            self::redirect("");
        }
    }

    public function action_del($param)
    {
        if (auth::authorized()) {
            $model = new {TemplateManagerName}();
            $model->del($param);
            self::redirect("/{TemplateControllerPath}/list");
        } else {
            self::redirect("");
        }
    }
}

?>
